package org.csu.small.controller.admin;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.csu.small.common.Constant;
import org.csu.small.common.UniformResponse;
import org.csu.small.entity.Slide;
import org.csu.small.service.ISlideService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author Rambo
 * @date 2020-06-08 9:02
 */
@Controller
@RequestMapping("/manage/slide/")
@Api(value = "API - ASlideController", description = "后台轮播图模块接口详情")
public class ASlideController {

    @Autowired
    private ISlideService slideService;

    @GetMapping("detail")
    @ResponseBody
    @ApiOperation(value = "轮播图详情")
    public UniformResponse<Slide> detail(Integer slideId){
        UniformResponse<Slide> response = slideService.detail(slideId);
        return response;
    }

    @PostMapping("delete")
    @ResponseBody
    @ApiOperation(value = "删除轮播图")
    public UniformResponse<String> delete(Integer slideId){
        UniformResponse<String> response = slideService.delete(slideId);
        return response;
    }

    @GetMapping("/list")
    @ResponseBody
    @ApiOperation(value = "查询所有轮播图")
    public UniformResponse<Object>  getSlidesList(
            @RequestParam(name = "pageNum", defaultValue = "1") int pageNum,
            @RequestParam(name = "pageSize", defaultValue = "10") int pageSize){
        return slideService.getSlideList(pageNum, pageSize);
    }

    @PostMapping("/add_slide")
    @ResponseBody
    @ApiOperation(value = "新增轮播图")
    public UniformResponse<String>  addSlide(Slide slide){
       return slideService.addSlide(slide);
    }

    @PostMapping("/edit_slide")
    @ResponseBody
    @ApiOperation(value = "编辑轮播图")
    public UniformResponse<String>  editSlide(Slide slide){
        return slideService.editSlide(slide);
    }

    @PostMapping("upload")
    @ResponseBody
    @ApiOperation(value = "上传图片")
    public UniformResponse<String> slide_upload(HttpServletRequest request, MultipartFile upload_file){
        String path = request.getSession().getServletContext().getRealPath("upload");
        //return productService.product_upload(upload_file, path);
        return null;
    }

    @GetMapping("set_show_status")
    @ResponseBody
    @ApiOperation(value = "修改轮播图状态")
    public UniformResponse<String> setSlideStatus(Integer slideId, Integer status){

        return slideService.setSlideStatus(slideId, status);
    }

}
